<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<html>
<head>
  <meta charset="UTF-8">
  <title>订单详情</title>
  <!-- jquery -->
  <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
  <!-- bootstrap -->
  <link rel="stylesheet" type="text/css"
        th:href="@{/bootstrap/css/bootstrap.min.css}"/>
  <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}">
  </script>
  <!-- layer -->
  <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
  <!-- common.js -->
  <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
<input type="hidden" id="orderId" th:value="${orderId}">
<div class="panel panel-default">
  <div class="panel-heading">秒杀订单详情</div>
  <table class="table" id="order">
    <tr>
      <td>商品名称</td>
      <td id="goodsName" colspan="3" ></td>
    </tr>
    <tr>
      <td>商品图片</td>
      <td colspan="2"><img id="goodsImg" width="200" height="200" /></td>
    </tr>
    <tr>
      <td>订单价格</td>
      <td colspan="2" id="goodsPrice" ></td>
    </tr>
    <tr>
      <td>下单时间</td>
      <td id="createDate" colspan="2" ></td>
    </tr>
    <tr>
      <td>订单状态</td>
      <td id="status" >
        <span>未支付</span>
        <span >待发货</span>
        <span >已发货</span>
        <span >已收货</span>
        <span >已退款</span>
        <span >已完成</span>
      </td>
      <td>
        <button class="btn btn-primary btn-block" type="submit"
                id="payButton">立即支付</button>
      </td>
    </tr>
    <tr>
      <td>收货人</td>
      <td colspan="2" id="addressee"></td>
    </tr>
    <tr>
      <td >收货地址</td>
      <td id="address" colspan="2"></td>
    </tr>
  </table>
</div>
<script>
    let orderId = $("#orderId").val();
    console.log(orderId);
    $(function () {
        getOrderDetail();
    });
    function getOrderDetail() {
        $.ajax({
            url: "/secKillOrder/detail",
            type: "GET",
            data: {
                orderId: orderId
            },
            success: function (data) {
                let res = JSON.parse(data);
                if (res.success) {
                    render(res.data);
                } else {
                    layer.msg(res.message);
                }
            },
            error: function () {
                layer.msg("客户端请求错误")
            }
        })

        function render(detail) {
            let goods = detail.goodsVo;
            let order = detail.order;
            $("#goodsName").text(goods.goodsName);
            $("#goodsImg").attr("src", goods.goodsImg);
            $("#goodsPrice").text(goods.seckillPrice);
            $("#createDate").text(new Date(order.createData).format("yyyy-MM-dd HH:mm:ss"));
            var status = order.status;
            var statusText = ""
            switch (status) {
                case 0:
                    statusText = "未支付";
                    break;
                case 1:
                    statusText = "待发货";
                    break;
                case 2:
                    statusText = "已发货";
                    break;
                case 3:
                    statusText = "已收货";
                    break;
                case 4:
                    statusText = "已退款";
                    break;
                case 5:
                    statusText = "已完成";
                    break;
            }
            $("#status").text(statusText);

            $("#addressee").text(order.userId);
            $("#address").text(order.deliveryAddrId);
        }
    }
</script>
</body>
</html>